<%-- 
    Document   : editObjekt
    Created on : 26.sep.2012, 18:59:25
    Author     : 500134
--%>
<%@include file="WEB-INF/jspf/header.jspf"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<%
    ArrayList<String> kategori;
    int energy;
    String cat;
    int id;
    kategori = db.DatabaseKobling.getCategories();
    String objekt = request.getParameter("oName");
    energy = db.DatabaseKobling.getArticleEnergyUse(objekt);
    cat = db.DatabaseKobling.getArticleCategory(objekt);
    id = db.DatabaseKobling.getArticleId(objekt);
%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <script>
            function isEmpty(str) {
                for (var intLoop = 0; intLoop < str.length; intLoop++)
                    if (" " != str.charAt(intLoop))
                        return false;
                return true;
            }

            function checkRequired(f) {
                var strError = "";
                for (var intLoop = 0; intLoop < f.elements.length; intLoop++)
                    if (null != f.elements[intLoop].getAttribute("required"))
                        if (isEmpty(f.elements[intLoop].value))
                            strError += "  " + f.elements[intLoop].name + "\n";
                if ("" != strError) {
                    alert("Required data is missing:\n" + strError);
                    return false;
                } else
                    return true
            }
        </script>
    </head>
    <body>
        <h2>Edit objekt</h2>
        <div class="nytt_objekt_area">  
            <div class="nytt_objekt_box">
                <form action="EditObjekt" onsubmit="checkRequired(this)" >&nbsp;
                    <input type="hidden" name="articleId" value="<%=id%>">
                    Navn: <input type="text" name="objektnavn" value="<%=objekt%>" required/><br/><br/>
                    Energiforbruk: <input type="number" name="energiforbruk" value="<%=energy%>" min="0" value="0" required/><br/><br/>
                    Kategori: <select name="kategori">
                        <%out.print("<option selected='selected'>" + cat + "</option>");
                            out.print("<option type='separator' disabled='disabled'>-------------------------------</option>");
                            for (int i = 0; i < kategori.size(); i++) {
                      out.print("<option>" + kategori.get(i) + "</option>");
                  }%>
                    </select><br/><br/>
                    <input type="submit" value="Lagre"/>
                    <a href="mineObjekter.jsp">Tilbake</a>
                </form>
            </div>
        </div>
    </body>
</html>
<%@include file="WEB-INF/jspf/footer.jspf"%>